package com.gexin.model.activity;

import com.gexin.common.utils.ArithUtil;
import com.gexin.model.activity.base.BaseMemberLevel;
import com.gexin.model.enums.MemberInfoEnum;

import java.lang.reflect.Member;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import static com.gexin.common.utils.ArithUtil.percent;
import static com.gexin.common.utils.ArithUtil.percentt;

/**
 * 业务名称:  t_member_level() 
 */
@SuppressWarnings("serial")
public class MemberLevel extends BaseMemberLevel<MemberLevel> {


	public static final MemberLevel dao = new MemberLevel();

//	积分转商品比例
	public static double integralExchangeCoinProportion(MemberLevel memberLevel) {
		Integer integralExchangeProductProportion = memberLevel.getIntegralExchangeProductProportion()==null?0:memberLevel.getIntegralExchangeProductProportion();
		double ProductAndCoinPercent = ProductAndCoinPercent = ArithUtil.div(memberLevel.getIntegralExchangeCoinProportion(), integralExchangeProductProportion);
		return ProductAndCoinPercent;
	}


//	积分转金币 汇率
	public static double integralExchangeCoinPercent(MemberLevel memberLevel) {
		int integralExchangeCoinRate = memberLevel.getIntegralExchangeCoinRate()==null?0:memberLevel.getIntegralExchangeCoinRate();
//        int integralExchangeCoinPercent = integralExchangeCoinRate / 100;
		double integralExchangeCoinPercent = percent(integralExchangeCoinRate, 100 );
		return integralExchangeCoinPercent;
	}

	//  准备金比例
	public static double resever(MemberLevel memberLevel) {
		Integer reserveProportion = memberLevel.getReserveProportion() == null ? 0 : memberLevel.getReserveProportion();
		double percent = percent(reserveProportion, 100 - reserveProportion);
		return percent;
	}

//	金币转现金比例
	public static double coinExchangeBalancePercent(MemberLevel memberLevel) {
		int coinExchangeMoneyProportion = memberLevel.getCoinExchangeMoneyProportion()==null?0:memberLevel.getCoinExchangeMoneyProportion();
//        int integralExchangeCoinPercent = coinExchangeMoneyProportion / 100;
		double integralExchangeCoinPercent = percent(coinExchangeMoneyProportion, 100 );
		return integralExchangeCoinPercent;
	}

	public static Boolean insertMemberLevel(Integer multi_incremetn, Integer integral_exchange_coin_proportion, Integer integral_exchange_product_proportion, Integer coin_exchange_money_proportion, Integer reserve_proportion, Integer integral_exchange_coin_rate, String tandard,Integer level) {
		MemberLevel memberLevel = new MemberLevel();
		memberLevel.setMultiIncremetn(multi_incremetn);
		memberLevel.setIntegralExchangeCoinProportion(integral_exchange_coin_proportion);
		memberLevel.setIntegralExchangeCoinProportion(integral_exchange_product_proportion);
		memberLevel.setCoinExchangeMoneyProportion(coin_exchange_money_proportion);
		memberLevel.setReserveProportion(reserve_proportion);
		memberLevel.setIntegralExchangeCoinRate(integral_exchange_coin_rate);
		BigDecimal standard= BigDecimal.valueOf(percentt(Double.parseDouble(tandard),1));
		memberLevel.setStandard(standard);
		memberLevel.setLevel(level);
		long time = new Date().getTime();
		memberLevel.setCreateTime(time);
		memberLevel.setUpdateTime(time);
		Boolean flag = false;
		flag = memberLevel.save();
		return flag;
	}

    public MemberLevel getMemberLevel(int level){
		MemberLevel memberLevel = MemberLevel.dao.findFirst("select * from t_member_level where level=" + level);
		return memberLevel;
	}

	public List<MemberLevel> getMemberLevelFans(){
		List<MemberLevel> memberLevelList = MemberLevel.dao.find("select * from t_member_level where level!=" + MemberInfoEnum.FIRST_LEVEL.getCode());
		return memberLevelList;
	}
	
}
